<template>
    <a-card :bordered="false">
        <div class="table-operator">
            <a-button shape="round" size="small" type="primary" icon="plus" @click="handleEdit({},'empForm','新增')">添加</a-button>
            <a-button shape="round" size="small" type="primary" icon="cloud-upload" @click="excelUpload">导入数据</a-button>
            <a-button shape="round" size="small" type="primary" icon="cloud-download" @click="excelDownload">导出数据</a-button>
        </div>

        <LTable
        ref="empListTable"
        size="middle"
        rowKey="keyId"
        :formAttributes="formAttributes"
        :columns="columns"
        axiosUrl="/SysEmpController/page"
        :showPagination="true"
        :showQueryForm="true"
      >
      <span slot="isUse" slot-scope="text,record">
          
            <a-icon v-if="record.isUse==1" type="check" :style="{ color: 'green' }"/>
            <a-icon v-else type="close" :style="{ color: 'hotpink',fontSize: '14px'}"/>
      </span>
        <a-icon type="check-circle" />
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record,'empForm',record.empName)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId,accountNo:record.accountNo},'/SysEmpController/del','empListTable')">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.isUse==1">
                  <a-popconfirm title="确定冻结吗?" @confirm="() => handlefreeze({keyId:record.keyId})">
                  <a>冻结</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-else>
                <a-popconfirm title="确定解冻吗?" @confirm="() => handleUnfreeze({keyId:record.keyId})">
                  <a>解冻</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                  <a-popconfirm title="确定密码重置吗?" @confirm="() => handleResetPwd({keyId:record.keyId})">
                  <a>密码重置</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        
    </LTable>
    <empForm ref="empForm" @close="refresh('empListTable')" @ok="refresh('empListTable')"></empForm> 
    <LExcelUpload ref="LExcelUpload" templateId="1714549154263592961" templateName="人员信息导入模板"></LExcelUpload>
    <LExcelDownload ref="LExcelDownload" templateId="1714549154263592961" templateName="人员信息"></LExcelDownload>
    </a-card>
</template>

<script>
import LTable from '@/components/lt/LTable'
import request from '@/utils/request'
import empForm from './empForm'
import {SysMixin} from '@/mixins/SysMixin'
import LExcelUpload from '@/components/lt/LExcelUpload'
import LExcelDownload from '@/components/lt/LExcelDownload'
import defaultSettings from '@/config/defaultSettings'
export default {
    name:'empList',
    components:{
       LTable,empForm,LExcelUpload,LExcelDownload
    },
    mixins:[SysMixin],
    data(){
        return{
            initDictCodes:defaultSettings.数据字典.组织下拉树,
            defaultSettings,
            formAttributes:[
                
                {field:'empName',label:'人员姓名',component:'input',condition:'like'},
                {field:'accountNo',label:'账号',component:'input',condition:'like'},
            ],
         
            columns:[
                {
                    title: '序号',
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                      return parseInt(index)+1;
                    }
                },
                 {
                    title: '组织',
                    dataIndex: 'orgNo',
                    customRender:(text)=>{
                        if(!text){
                            return ''
                        }else{
                            return this.dictText(defaultSettings.数据字典.组织下拉树,text)
                        }
                    }
                },
                
                {
                    title: '人员编号',
                    dataIndex: 'empNo',
                },
                {
                    title: '人员姓名',
                    dataIndex: 'empName'
                    
                },
                {
                    title: '登陆账号',
                    dataIndex: 'accountNo'
                    
                },
                {
                    title: '状态',
                    dataIndex: 'isUse',
                    scopedSlots: { customRender: 'isUse' }
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    width: '120px',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            
        }
    },
    created(){
       
    },
    methods:{
        handlefreeze(params){
            var that = this;
            request.get('/SysEmpController/freeze',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        handleUnfreeze(params){
            var that = this;
            request.get('/SysEmpController/unfreeze',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        handleResetPwd(params){
            var that = this;
            request.get('/SysEmpController/resetPwd',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        excelUpload(){
            this.$refs['LExcelUpload'].show();
        },
        excelDownload(){
            this.$refs['LExcelDownload'].show();
        }
    }
}
</script>